import { Entity, PrimaryColumn, Column, BeforeInsert } from 'typeorm';
import { uuidv7 } from 'uuidv7';

@Entity('apartment_users')
export class ApartmentUser {
  @PrimaryColumn('uuid')
  id: string;

  @Column({ nullable: true, comment: '昵称' })
  nickname?: string;

  @Column({ nullable: true, comment: '名字' })
  name?: string;

  @Column({ nullable: false, unique: true, comment: '邮箱' })
  email: string;

  @Column({ nullable: false, comment: '密码' })
  password: string;

  @Column({ name: 'avatar_url', nullable: true, comment: '头像地址' })
  avatarUrl?: string;

  @Column({ name: 'level', nullable: true, default: '免费用户', comment: '用户等级' })
  level?: string;

  @Column({ name: 'expiration_date', nullable: true, comment: '等级过期时间' })
  expirationDate?: string;

  @BeforeInsert()
  generateId() {
    if (!this.id) {
      this.id = uuidv7();
    }
  }
}
